package com.ambimmort.shj.action.system.property;

import cn.net.greenet.db.HibernateUtil;
import cn.net.greenet.db.bean.Systemproperty;
import com.ambimmort.shj.service.system.property.SystemPropertyService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by Josh on 2015/7/31.
 */
@Controller("/action/system/setlistproperty1.do")
public class SetListProperty {
    @Autowired
    private SystemPropertyService systemPropertyService;

    /**
     *
     * @param request
     * @param response
     * @param property
     * @return
     */
    @RequestMapping("/action/system/setlistproperty1.do")
    @ResponseBody
    public String setlistproperty_system(HttpServletRequest request,HttpServletResponse response, @RequestParam("property") String property){
//        SessionFactory sf = HibernateUtil.getSessionFactory();
//        Session session = sf.openSession();
//        session.clear();
//        Transaction tx = session.beginTransaction();
//        JSONArray jsonArr = JSONArray.fromObject(property);
//        JSONObject jo = null;
//        Systemproperty systemProperty =null;
        try {
            systemPropertyService.setListProperty(property);
//            tx.commit();
            return "{\"result\":\"true\"}";
        } catch (Exception e) {
            e.printStackTrace();
//            tx.rollback();
            return "{\"result\":\"false\"}";
        }
//        finally {
//            session.close();
//        }
    }
}
